package com.xiangty.ssmtemplate.controller;

import com.xiangty.ssmtemplate.common.Result;
import com.xiangty.ssmtemplate.entity.User;
import com.xiangty.ssmtemplate.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Classname IndexController
 * @Description TODO
 * @Date 2020/4/18 16:40
 * @Created by xiangty
 */
@Controller
public class IndexController {

    private static final Logger LOGGER = LoggerFactory.getLogger(IndexController.class);

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/")
    public String indexPage() {
        return "index";
    }

    @RequestMapping(value = "/queryUserList")
    @ResponseBody
    public Result queryUserList() {
        // 打印一下日志，检验下日志配置是否有正常
        LOGGER.info("iiiiiiiiiii");
        LOGGER.debug("dddddddd");
        LOGGER.warn("wwwwwwwwww");
        LOGGER.error("eeeeeeeee");

        List<User> userList = userService.queryUserList();
        userList.forEach(user -> {
            LOGGER.info("id:{}", user.getId());
            LOGGER.info("username:{}", user.getUsername());
            LOGGER.info("password:{}", user.getPassword());
        });

        return Result.ok(userList);
    }

}
